package com.AUI.components
{
	import com.AUI.*;
	import com.AUI.define.style.*;
	
	import flash.text.*;
	/**
	 * Label.
	 * @author HuangMinPing
	 * @site www.AminLab.com
	 */
	public class Label extends AComponent
	{
		/**
		 * [element] text.
		 */
		public var e_text:TextField = new TextField;
		/**
		 * Constructor.
		 */
		public function Label(label:String = '')
		{
			// init attributes
			depth = 1;
			align = true;
			// init elements
			e_text.mouseEnabled = false;
			e_text.text = label;
			elements.addChild(e_text);
			
			/**************** INITCOMPLETE ****************/
			Object(this).constructor == Label && initComplete();
		}
		/**
		 * Get or set the text of the label.
		 */
		override public function set value(variable:*):void
		{
			var label:String = variable as String;
			e_text.text = label;
			updateContentBox();
		}
		override public function get value():*
		{
			return e_text.text;
		}
		/**
		 * @private
		 */
		override protected function updateDrawStyle():void
		{
			super.updateDrawStyle();
			// update text
			var font:FONT = drawStyle.font; 
			var textFormat:TextFormat = new TextFormat(font.family,font.size,font.color,font.bold,font.italic,font.underline,null,null,font.align);
			e_text.defaultTextFormat = textFormat;
			e_text.setTextFormat(textFormat);
		}
		/**
		 * @private
		 */
		override protected function resizeBoxModel():void
		{
			if(e_text.text)
			{
				e_text.autoSize = TextFieldAutoSize.LEFT;
			}
			else
			{
				e_text.autoSize = TextFieldAutoSize.NONE;
				e_text.width = e_text.height = 0;
			}
			// done
			super.resizeBoxModel();
		}
	}
}